﻿using System;
using System.Web.Services;
using Monkey.Warrenty.Biz;
using Monkey.Warrenty.Enum;

namespace MonkeyWarranty.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        #region Properties

        private static InstantTicketBiz _instantTicketBiz;
        private static InstantTicketBiz InstantTicketManager
        {
            get { return _instantTicketBiz ?? (_instantTicketBiz = new InstantTicketBiz()); }
        }

        protected int NewTicketCount
        {
            get { return InstantTicketManager.GetTicketCount(InstantTicketStatus.Received); }
        }

        protected int ProcessingTicketCount
        {
            get { return InstantTicketManager.GetTicketCount(InstantTicketStatus.Processing); }
        }

        //protected int CompletedTicketCount
        //{
        //    get { return InstantTicketManager.GetTicketCount(InstantTicketStatus.Completed); }
        //}

        private static WarrantyTicketBiz _warrantyTicketBiz;
        private static WarrantyTicketBiz WarrantyTicketManager
        {
            get { return _warrantyTicketBiz ?? (_warrantyTicketBiz = new WarrantyTicketBiz()); }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                rptTicketEmployeeCounts.DataSource = InstantTicketManager.GetInstantTicketEmployeeCount(
                       new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1), DateTime.Today);
                rptTicketEmployeeCounts.DataBind();
            }
        }

        [WebMethod(EnableSession = true)]
        public static object TicketListByFilter(int jtStartIndex, int jtPageSize, string jtSorting)
        {
            //System.Threading.Thread.Sleep(1000);
            var ticketCount = WarrantyTicketManager.GetActiveTicketCount(jtStartIndex, jtPageSize, jtSorting);
            var warrantyTicketViews = WarrantyTicketManager.GetActiveTickets(jtStartIndex, jtPageSize, jtSorting);
            
            return new { Result = "OK", Records = warrantyTicketViews, TotalRecordCount = ticketCount };
        }
    }
}
